package cc.vv.btpartyjob.jobactivities.delegate

import android.support.v4.view.ViewPager
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.adapter.JniViewPageAdapter
import cc.vv.btpartyjob.jobactivities.R
import cc.vv.mvp.delegate.BaseAppDelegate

/**
 * 项目查询托管类
 * Created by Chen.qi on 2018/10/24.
 */
class HeXinJiaZhiActivityDelegate : BaseAppDelegate() {

    /**
     * TextView数组数据
     */
    private var textArr = arrayListOf<TextView>()

    override fun initWidget() {
        val normal = getView<TextView>(R.id.tv_aszHj_projectNormal)
        val warning = getView<TextView>(R.id.tv_aszHj_projectWarning)
        val postpone = getView<TextView>(R.id.tv_aszHj_projectPostpone)
        val cancel = getView<TextView>(R.id.tv_aszHj_projectCancel)
        val pdSp = getView<TextView>(R.id.tv_aszHj_projectPDSP)
        textArr = arrayListOf(normal, warning, postpone, cancel, pdSp)
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_shehui_zhuyi_hexin_jiazhi
    }

    /**设置标题title*/
    fun setTopBarTitle(topBarTitle: String) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_aszHj_topBar)
        titleBar?.setTitle(topBarTitle)
    }


    /**设置标题右边按钮点击事件*/
    fun setTitleBackBtnOnClick(event: BaseTopBarView.EventInterface) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_aszHj_topBar)
        titleBar?.setEventInterface(event)
    }


    /**
     * 设置adatper
     */
    fun setAdapterData(adapter: JniViewPageAdapter) {
        getView<ViewPager>(R.id.vp_aszHj_projectQueryPager)?.adapter = adapter
    }

    /**
     * 设置viewpager位置
     */
    fun setViewPagerPos(currentPos: Int) {
        getView<ViewPager>(R.id.vp_aszHj_projectQueryPager)?.currentItem = currentPos
        setTextStatus(currentPos)
    }


    /**
     * 设置状态
     */
    fun setTextStatus(pagerPos: Int) {
        for (i in 0 until textArr.size) {
            textArr[i].isSelected = false
        }
        textArr[pagerPos].isSelected = true
    }


    /**
     * 设置viewPager的监听
     */
    fun bindViewPagerListener(listener: ViewPager.OnPageChangeListener) {
        getView<ViewPager>(R.id.vp_aszHj_projectQueryPager)?.addOnPageChangeListener(listener)
    }

    //##############################搜索逻辑#############################//
    /**搜索布局显示*/
    fun showSearchView(isShowSearch: Boolean) {
        val searchTop = getView<RelativeLayout>(R.id.rl_aszHj_searchTop)
        if (isShowSearch) {
            searchTop?.visibility = View.VISIBLE
        } else {
            searchTop?.visibility = View.GONE
        }
    }

    /**
     * 搜索布局是否显示
     */
    fun getSearchShow(): Boolean {
        val isShow: Boolean
        val searchTop = getView<RelativeLayout>(R.id.rl_aszHj_searchTop)
        isShow = searchTop?.visibility == View.VISIBLE
        return isShow
    }

    /**
     * 获取输入的文本
     */
    fun getInputSearchText(): String {
        val etSearch = getView<TextView>(R.id.et_aszHj_inputSearch)
        return etSearch?.text.toString().trim()
    }

}